package com.hl.toolkit.server.util;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

import java.io.File;
import java.util.Hashtable;


public class QRCodeEvents {   
       
    public static void main(String []args)throws Exception{   
        String text = "你好";   
        int width = 200;   
        int height = 200;   
        String format = "png";   
        Hashtable hints= new Hashtable();   
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
         BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height,hints);
         File outputFile = new File("zxingImg/new_"+System.currentTimeMillis()+".png");   
         MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);
            
    }   
    
    
    public static void Qrcode(String text,int width,int height,String file) throws Exception{   
    	String result="";
         String format = "png";   
        Hashtable hints= new Hashtable();   
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
         BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height,hints);
         File outputFile = new File(file);   
         MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);
     }   
}  
